
<template>
  <div class="app-container">
    <!--    <el-image src="/images/formIcon/benji1.svg" style="background-color: black"></el-image>-->
    <!--    <el-image src="/images/formIcon/benji2.svg" ></el-image>-->
    <el-form :model="searchForm" :inline="true" @submit.native.prevent>
      <el-row>
        <el-col :span="20">
          <!-- <el-form-item label="任务单号:">
            <el-input v-model="searchForm.jobId" style="width:165px" placeholder="任务单号" />
          </el-form-item> -->

          <el-form-item>
            <el-input v-model="searchForm.fuzzy" style="width:250px" placeholder="项目名称/受检单位/任务单号" clearable @keyup.enter.native="handleSearch" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" class="iconfont icon-chaxun1" @click="handleSearch">查询</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="4" style="text-align: right;">
          <el-button type="text" icon="el-icon-s-operation" style="margin-right: 20px;" @click="handleInStockListDetail">样品编码转换设置</el-button>
          <el-button type="text" icon="el-icon-refresh" @click="handleSearch">刷新</el-button>
        </el-col>
      </el-row>
    </el-form>
    <div>
      <el-table
        ref="stockTable"
        stripe
        border
        :data="taskData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{background:'#ECF3FC'}"
        style="width: 100%"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span>
                暂无审核信息
              </span>
            </div>
          </div>
        </template>
        <el-table-column type="index" width="55" align="center" label="序号" />
        <el-table-column prop="jobId" label="任务单号" width="130px" align="center" />
        <el-table-column prop="projectName" label="项目名称" min-width="150px" align="center" />
        <el-table-column prop="inspectionName" label="受检单位" align="center" />
        <el-table-column label="检测类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.checkType | checkTypeFiles }}
          </template>
        </el-table-column>
        <!--<el-table-column prop="totalSamples" label="样品总数" min-width="100px" align="center" />-->
        <el-table-column prop="amount" label="入库样品数" align="center" />
        <!--<el-table-column prop="outBoundSamples" label="出库样品数" width="100px" align="center" />-->
        <el-table-column fixed="right" align="center" label="操作" width="150">
          <template slot-scope="scope">
            <!--<el-button v-if="checkSample(scope.row)" type="text" @click="handleSample(scope.row)">合样</el-button>-->
            <el-button type="text" @click="handleDetail(scope.row)">入库</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="float: right">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>

    <!-- 样品编码转换设置 -->
    <el-dialog title="样品编码转换设置" :visible.sync="inStockListVisible" center width="23%" max-height="300px">
      <div style="width: 500px;margin:0 auto">
        <el-form :model="inStockListForm" label-width="120px">
          <el-form-item label="样品编码转换:">
            <el-radio-group v-model="inStockListForm.enableStatus">
              <el-radio label="1">开启</el-radio>
              <el-radio label="2">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;float: right;">
        <el-button @click="inStockListVisible=false">取消</el-button>
        <el-button type="primary" @click="InStockListDialog">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as stockServer from '@/api/stock'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import sampleDialog from './index/sampleDialog.vue'
import commonMixins from '../../mixins/commonMixins.js'
const STOCK_STATUS = {
  '6': '在库',
  '7': '部分出库',
  '8': '已出库'
}
const CHECK_STATUS = {
  '0': '单次',
  '1': '周',
  '2': '月',
  '3': '季度',
  '4': '半年',
  '5': '年'
}
export default {
  components: { Pagination, sampleDialog },
  filters: {
    statusQualityFilter(status) {
      const statusMap = {
        '6': '',
        '7': 'success',
        '8': 'success'
      }
      return statusMap[status]
    }
  },
  mixins: [commonMixins],
  data() {
    return {
      STOCK_STATUS,
      CHECK_STATUS,
      taskData: [],
      searchForm: {
        fuzzy: '',
        jobId: '',
        sampItemId: '',
        sampStatus: '',
        date: '',
        pageNumber: 1,
        pageSize: 10
      },
      total: 0,
      approveVisible: false,
      sampleVisible: false,
      sampleDetailForm: {
        collectUser: '', // 采样员
        sampleProperties: '',
        sampleFixative: '',
        collectRemark: '',
        collectLocation: '',
        collectIamge1: '',
        collectIamge2: '',
        collectIamge3: '',
        collectIamge4: '',
        factorName: ''
      },
      currentSample: '',
      approveForm: {
        sampItemId: '',
        auditFlag: '1',
        auditReason: ''
      },
      sampleImage: '',
      sampleImageList: [],
      multipleSelection: [],
      downVisible: false,
      recordForm: {
        taskId: '',
        classId: '',
        secClassId: '',
        sampleDate: ''
      },
      classArray: [],
      secClassArray: [],
      sampleDetails: [],
      sampleDataInfo: [],
      sampleSecInfo: [],
      currentSelectionRow: {
        jobId: '',
        secdClassName: '',
        storeData: ''
      },

      inStockListVisible: false,
      inStockListForm: {
        enableStatus: '1'
      },
    }
  },
  created() {
    this.handleSearch()
  },
  methods: {
    checkSample(sample) {
      // console.log(sample);
      return sample.checkType == '1' && sample.inBoundSamples == 0
    },
    handleSearch() {
      stockServer.queryWarehousingListApi(this.searchForm).then(res => {
        // console.log(res.result.records);
        if (res.code === 200 && res.result) {
          this.taskData = res.result.records || []
          this.total = res.result.total
        }
      })
    },
    handleDetail(row) {
      // console.log(row);
      if (row.checkType == '0') { // 委托检测
        if (row.amount > 0) {
          this.$router.push({ path: `/other/entrustWarehousing`, query: row })
        } else {
          this.$message({
            type: 'warning',
            message: '委托检测，入库样品总数不能为0'
          })
        }
      } else {
        // 来样送检
        this.$router.push({ path: `/other/incomingSampleWarehousing`, query: row })
      }
    },
    handleSample(row) {
      this.dialogObj.show = true
    },

    // 样品编码转换设置
    handleInStockListDetail() {
      // 查询样品编码设置信息
      stockServer.findBySamplesCodeSet().then(res => {
        if (res.code === 200) {
          if (res.result != null){
            this.inStockListForm.enableStatus = res.result.enableStatus
          }
        }
        this.inStockListVisible = true
      })
    },

    // 保存样品编码转换设置
    InStockListDialog() {
      stockServer.samplesCodeSetint(this.inStockListForm).then(res => {
        if (res.code === 200) {
          this.$notify({
            title: '成功',
            message: res.message,
            type: 'success'
          })
          this.inStockListVisible = false
          this.handleSearch()
        } else {
          this.$notify({
            title: '失败',
            message: res.message,
            type: 'error'
          })
        }
      })
    },

  }
}
</script>

<style scoped lang="scss" >
  .clearfix {
    line-height: 40px;
    display: flex;
  }
  /deep/ .el-table__header-wrapper .el-checkbox {
    display: none;
  }
  /deep/ .el-table__fixed-header-wrapper .el-checkbox {
    display: none;
  }
  .table-item /deep/ .el-table__header-wrapper .el-checkbox {//table-item 父级类名
    display: none;
  }
</style>
